home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / fansi.zip / RAWTEST.LC < prev    next >
Text File  |  1985-11-18  |  3KB  |  73 lines

  1. /*------ rawtest.c -------------------------------------------------
  2. Lattice C program to demonstrate the difference in speed between
  3. DOS's raw and cooked modes when writing to the DOS console.
  4. Requires setraw.c; make the demo as follows:
  5.     lc setraw rawtest
  6.     link \lc\s\c rawtest setraw,rawtest,,\lc\s\lc
  7. and run it by typing
  8.     rawtest
  9.  
  10. Note- Lattice C's raw mode (i.e. using mode "rb" or "wb" with fopen)
  11. is not the same as DOS's raw mode, and does not affect speed.
  12.  
  13. What does affect speed is whether output is performed with single-character
  14. DOS calls, which is the default.  To get a speed improvement, you must 
  15. open "con" WITHOUT a trailing colon, and use that file for high-speed output;
  16. see section 5.2 (Device I/O) of the Lattice manual.
  17.  
  18. When using MS-DOS raw mode, the console is in totally unbuffered mode-
  19. echo is turned off, no printer echoing is done, and no line editing
  20. is done, regardless of which file setraw was applied to.  This means
  21. that the console must be in non-raw ("cooked") mode for line-oriented
  22. console input to work properly.
  23.  
  24. Note: no speed difference will be noticed when using the standard console
  25. driver ANSI.SYS that comes with DOS; you must be using NANSI.SYS to
  26. get massively fast output.  
  27. To use nansi.sys, insert the following line in \config.sys:
  28.     device = nansi.sys
  29. and put nansi.sys on the top level directory; the system will load
  30. it at boot time.
  31. (If there was already a line invoking plain old ansi.sys, remove it.)
  32. --------------------------------------------------------------------*/
  33.  
  34. #include "\lc\stdio.h"
  35.  
  36. char    response[128];
  37.  
  38. main(argc, argv)
  39. int    argc;
  40. char    **argv;
  41. {
  42.     FILE    *fp;
  43.     int    fd;
  44.     int    old_rawness;
  45.     int    i;
  46.  
  47.     fp = fopen("con", "w");
  48.     if (fp == NULL) fprintf(stderr, "can't open 'con'!");
  49.     fd = fileno(fp);        /* get Level 1 file descriptor */
  50.     old_rawness = getraw(fd);    /* Save old raw/cooked state */
  51.  
  52.     setraw(fd, 0);            /* make sure we're in cooked mode */
  53.  
  54.     puts("Cooked mode test (hit return):");
  55.     gets(response);
  56.     fprintf(fp, "\033[2J");        /* clear screen */
  57.     for (i=0; i<20; i++)
  58.         fprintf(fp, "This is cooked mode!  Why is it so darned slow? %d\n", i);
  59.     fflush(fp);
  60.  
  61.     puts("Raw mode test (hit return):");
  62.     gets(response);            /* must be in cooked mode to use gets */
  63.     setraw(fd, 1);            /* enter raw mode */
  64.     fprintf(fp, "\033[2J");        /* clear screen */
  65.     for (i=0; i<20; i++)
  66.         fprintf(fp, "-- This is raw mode- it's clearly faster than cooked! %d\n", i);
  67.     fflush(fp);            /* finish writing while in raw mode */
  68.     setraw(fd, old_rawness);    /* go back to old raw/cooked state  */
  69.  
  70.     fclose(fp);
  71. }
  72.  
  73.